package com.zuthub.system.service.impl;

import java.util.List;
import com.zuthub.common.utils.DateUtils;
import com.zuthub.system.domain.SysMember;
import com.zuthub.system.mapper.SysMemberMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zuthub.system.mapper.SysMemberApproveMapper;
import com.zuthub.system.domain.SysMemberApprove;
import com.zuthub.system.service.ISysMemberApproveService;

/**
 * 入社审批Service业务层处理
 * 
 * @author zuthub
 * @date 2021-04-17
 */
@Service
public class SysMemberApproveServiceImpl implements ISysMemberApproveService 
{
    @Autowired
    private SysMemberApproveMapper sysMemberApproveMapper;

    @Autowired
    private SysMemberMapper sysMemberMapper;
    /**
     * 查询入社审批
     * 
     * @param approveId 入社审批ID
     * @return 入社审批
     */
    @Override
    public SysMemberApprove selectSysMemberApproveById(Long approveId)
    {
        return sysMemberApproveMapper.selectSysMemberApproveById(approveId);
    }

    /**
     * 查询入社审批列表
     * 
     * @param sysMemberApprove 入社审批
     * @return 入社审批
     */
    @Override
    public List<SysMemberApprove> selectSysMemberApproveList(SysMemberApprove sysMemberApprove)
    {
        return sysMemberApproveMapper.selectSysMemberApproveList(sysMemberApprove);
    }

    /**
     * 新增入社审批
     * 
     * @param sysMemberApprove 入社审批
     * @return 结果
     */
    @Override
    public int insertSysMemberApprove(SysMemberApprove sysMemberApprove)
    {
        sysMemberApprove.setCreateTime(DateUtils.getNowDate());
        String approved = sysMemberApprove.getApproved();
        if (approved == null || "".equals(approved)) {
            sysMemberApprove.setApproved("否");
        }
        return sysMemberApproveMapper.insertSysMemberApprove(sysMemberApprove);
    }

    /**
     * 修改入社审批
     * 
     * @param sysMemberApprove 入社审批
     * @return 结果
     */
    @Override
    public int updateSysMemberApprove(SysMemberApprove sysMemberApprove)
    {
        sysMemberApprove.setUpdateTime(DateUtils.getNowDate());
        return sysMemberApproveMapper.updateSysMemberApprove(sysMemberApprove);
    }

    /**
     * 批量删除入社审批
     * 
     * @param approveIds 需要删除的入社审批ID
     * @return 结果
     */
    @Override
    public int deleteSysMemberApproveByIds(Long[] approveIds)
    {
        return sysMemberApproveMapper.deleteSysMemberApproveByIds(approveIds);
    }

    /**
     * 删除入社审批信息
     * 
     * @param approveId 入社审批ID
     * @return 结果
     */
    @Override
    public int deleteSysMemberApproveById(Long approveId)
    {
        return sysMemberApproveMapper.deleteSysMemberApproveById(approveId);
    }

    @Override
    public int approveMember(SysMemberApprove sysMemberApprove) {
        SysMember sysMember = new SysMember();
        BeanUtils.copyProperties(sysMemberApprove,sysMember);
        sysMember.setPost("社员");
        sysMember.setMemberId(null);
        sysMemberApproveMapper.deleteSysMemberApproveById(sysMemberApprove.getApproveId());
        return sysMemberMapper.insertSysMember(sysMember); }

    @Override
    public int approveBatch(long[] approveIds) {
        for (long approveId : approveIds) {
            SysMemberApprove sysMemberApprove = sysMemberApproveMapper.selectSysMemberApproveById(approveId);
            SysMember sysMember = new SysMember();
            BeanUtils.copyProperties(sysMemberApprove,sysMember);
            sysMember.setPost("社员");
            sysMember.setMemberId(null);
            sysMemberMapper.insertSysMember(sysMember);
            sysMemberApproveMapper.deleteSysMemberApproveById(approveId);
        }
        return approveIds.length;
    }
}
